package com.jz.community.moduleshoppingguide.neighbor.ui.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.glideConfig.GlideApp;
import com.jz.community.basecomm.utils.RxImageTool;
import com.jz.community.moduleshoppingguide.R;
import com.jz.community.moduleshoppingguide.neighbor.bean.CirclePersonsBean;

import java.util.List;


public class NeighborPersonsAdapter extends BaseQuickAdapter<CirclePersonsBean.EmbeddedBean.ContentBean, BaseViewHolder> {

    public NeighborPersonsAdapter(int layoutResId, @Nullable List<CirclePersonsBean.EmbeddedBean.ContentBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CirclePersonsBean.EmbeddedBean.ContentBean entity) {
        //获取屏幕宽高
        WindowManager wm = (WindowManager) mContext.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
        assert wm != null;
        int screen_width = wm.getDefaultDisplay().getWidth();//获取屏幕宽度
        int screen_height = wm.getDefaultDisplay().getHeight();//获取屏幕高度

        LinearLayout parent = helper.getView(R.id.item_circle_persons_parent);
        ImageView avatar = helper.getView(R.id.item_circle_persons_avatar);

        GlideApp.with(mContext)
                .load(entity.getHeadImg())
                .placeholder(R.mipmap.image_default)
                .error(R.mipmap.image_default)
                .into(avatar);

        helper.setText(R.id.item_circle_persons_name, entity.getNickName());

        ViewGroup.LayoutParams lp1 = parent.getLayoutParams();
        lp1.width = (screen_width - RxImageTool.dp2px(20 * 6)) / 5;
        parent.setLayoutParams(lp1);

        ViewGroup.LayoutParams lp2 = avatar.getLayoutParams();

        lp2.width = (screen_width - RxImageTool.dp2px(20 * 6)) / 5;
        lp2.height = (screen_width - RxImageTool.dp2px(20 * 6)) / 5;
        avatar.setLayoutParams(lp2);


    }
}
